#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:02操作sqlite3数据库插入.py
# author: 马国鑫
# datetime:2022/4/17 21:25
# software: PyCharm

"""
this is function  description 
"""

# import module your need

import sqlite3

conn = sqlite3.connect(r'D:\Python_code\python_web_study\db\demo.db')
cur = conn.cursor()

sql = 'insert into t_person(pname, age) values(?,?)'

try:
    cur.execute(sql, ('马国鑫', 19))
    # 提交事务
    conn.commit()
    print('插入数据成功')
except Exception as e:
    print(e)
    conn.rollback()
    print('插入数据失败')
finally:
    cur.close()
    conn.close()